<?php

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
/* 代码增加 by www.68ecshop.com strat */
require(dirname(__FILE__) . '/includes/lib_comment.php');
/* 代码增加 by www.68ecshop.com end */
if ((DEBUG_MODE & 2) != 2)
{
    $smarty->caching = true;
}

/* 清除缓存 */
clear_cache_files();

/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */

/* 获得页面的缓存ID */
$cache_id = sprintf('%X', crc32($_CFG['lang']));

if (!$smarty->is_cached('store_list.dwt', $cache_id))
{
    /* 如果页面没有被缓存则重新获得页面的内容 */

    assign_template();
    $position = assign_ur_here(0, '门店自提');
    $smarty->assign('page_title',           $position['title']);     // 页面标题
    $smarty->assign('ur_here',              $position['ur_here']);   // 当前位置

    $smarty->assign('categories',           get_categories_tree(0)); // 分类树
    $smarty->assign('helps',                get_shop_help());        // 网店帮助
    $smarty->assign('top_goods',            get_top10());            // 销售排行

    $smarty->assign('best_goods',           get_recommend_goods('best'));
    $smarty->assign('new_goods',            get_recommend_goods('new'));
    $smarty->assign('hot_goods',            get_recommend_goods('hot'));
    $smarty->assign('promotion_goods',      get_promote_goods());
    $smarty->assign('promotion_info', get_promotion_info());

	$store_list = get_storelist();
	$smarty->assign('st_list', $store_list);
	$smarty->assign('json_datas',json_encode($store_list));


    $smarty->assign('keywords',    htmlspecialchars($meta['keywords']));
    $smarty->assign('description', htmlspecialchars($meta['cat_desc']));

    $keywords = '';
    $goon_keywords = ''; //继续传递的搜索关键词

    if (isset($_REQUEST['keywords']))
    {
        $keywords = addslashes(htmlspecialchars(urldecode(trim($_REQUEST['keywords']))));
        $pager['search']['keywords'] = $keywords;
        $search_url = substr(strrchr($_POST['cur_url'], '/'), 1);

        $smarty->assign('search_value',    stripslashes(stripslashes($keywords)));
        $smarty->assign('search_url',       $search_url);

        $goon_keywords = urlencode($_REQUEST['keywords']);
    }
    $smarty->assign('stores_cat',    get_cat_stores($keywords));
    assign_dynamic('store_cat');
}

$smarty->display('store_list.dwt', $cache_id);

function get_cat_stores($requirement='')
{
    //增加搜索条件，如果有搜索内容就进行搜索    
    if ($requirement != '')
    {
        $sql = 'SELECT * FROM ' .$GLOBALS['ecs']->table('store') . ' WHERE name like \'%' . $requirement . '%\' ';
    }
    else 
    {
        
        $sql = 'SELECT * FROM ' .$GLOBALS['ecs']->table('store');
    }

    $res = $GLOBALS['db']->getAll($sql);

    return $res;
}

?>